class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> map;
        int max_len = 0,start = 0;
        for (int i = 0; i < s.length(); ++i) {
            char cur_char = s[i];
            if (map.find(cur_char) != map.end() && map[cur_char] >= start) {
                start = map[cur_char] + 1;
            }
            map[cur_char] = i;
            max_len = max(max_len, i - start + 1);
        }
        return max_len;
    }
};
